package com.wsl.config;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

import java.io.IOException;


/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 10:55 2017/11/24
 * @Modified by:
 */
@Configuration
@ComponentScan("com.wsl")
@PropertySource("classpath:wsl.properties")
public class ElConfig {
    @Value("I Love You")
    private String  normal;//注入普通字符串
    @Value("#{systemProperties['os.name']}")
    private String osName;//注入操作系统属性
    @Value("#{T(java.lang.Math).random()*100.0}")
    private double randomNumber;//注入表达式结果
    @Value("#{demoService.another}")
    private String fromAnther;//注入其他Bean属性
    @Value("http://www.baidu.com")
    private Resource testUrl;//注入网址资源
    @Value("${book.name}")
    private String bookName;//注入配置文件
    @Value("classpath:wpq.sql")
    private Resource resourceSql;//注入文件资源
    @Autowired
    private Environment environment;
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigurer(){
        return  new PropertySourcesPlaceholderConfigurer();
    }

    public void outputResource() throws IOException {

            System.out.println(normal);
            System.out.println(osName);
            System.out.println(randomNumber);
            System.out.println(fromAnther);
            System.out.println(IOUtils.toString(resourceSql.getInputStream()));
            System.out.println(bookName);
            System.out.println(environment.getProperty("book.author"));

    }
}